import unittest
from typing import List


class Solution:
    def maximumUniqueSubarray(self, nums: List[int]) -> int:
        ret = 0
        nums_set = set()
        left = 0
        cur = 0
        for right, val in enumerate(nums):
            while val in nums_set and left <= right:
                cur -= nums[left]
                ret = max(ret, cur)
                nums_set.remove(nums[left])
                left += 1
            nums_set.add(val)
            cur += val
            ret = max(ret, cur)
        return ret

class Test(unittest.TestCase):

    def test_case1(self):
        ret = Solution().maximumUniqueSubarray([4,2,4,5,6])
        self.assertEqual(17, ret)